package cn.sfrog.project.biz.admin.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import cn.sfrog.common.annotation.RepeatSubmit;
import cn.sfrog.project.biz.admin.domain.vo.BizLiveRoomFormVO;
import cn.sfrog.project.biz.admin.domain.vo.BizLiveRoomQueryVO;
import cn.sfrog.project.biz.admin.domain.vo.BizLiveRoomVO;
import cn.sfrog.project.biz.admin.service.IBizLiveRoomService;
import cn.sfrog.system.domain.vo.BizStatusChangeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.sfrog.common.annotation.Log;
import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.domain.AjaxResult;
import cn.sfrog.common.enums.BusinessType;

import cn.sfrog.common.utils.poi.ExcelUtil;
import cn.sfrog.common.core.page.TableDataInfo;

/**
 * 直播房间Controller
 * 
 * @author dev
 * @date 2024-05-23
 */
@Api(tags = "直播房间接口")
@RestController
@RequestMapping("/biz/room")
public class BizLiveRoomController extends BaseController {
    @Resource
    private IBizLiveRoomService bizLiveRoomService;

    /**
     * 查询直播房间列表
     */
    @ApiOperation("查询列表")
    @PreAuthorize("@ss.hasPermi('biz:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizLiveRoomQueryVO queryVO) {
        startPage();
        List<BizLiveRoomVO> list = bizLiveRoomService.selectBizLiveRoomList(queryVO);
        return getDataTable(list);
    }

    /**
     * 导出直播房间列表
     */
    @ApiOperation("导出")
    @PreAuthorize("@ss.hasPermi('biz:room:export')")
    @Log(title = "直播房间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizLiveRoomQueryVO query) {
        List<BizLiveRoomVO> list = bizLiveRoomService.selectBizLiveRoomList(query);
        ExcelUtil<BizLiveRoomVO> util = new ExcelUtil<BizLiveRoomVO>(BizLiveRoomVO.class);
        util.exportExcel(response, list, "直播房间数据");
    }

    /**
     * 获取直播房间详细信息
     */
    @ApiOperation("获取详情")
    @PreAuthorize("@ss.hasPermi('biz:room:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bizLiveRoomService.selectBizLiveRoomById(id));
    }

    /**
     * 新增直播房间
     */
    @ApiOperation("新增")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:room:add')")
    @Log(title = "直播房间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizLiveRoomFormVO form) {
        return toAjax(bizLiveRoomService.insertBizLiveRoom(form));
    }

    /**
     * 修改直播房间
     */
    @ApiOperation("修改")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:room:edit')")
    @Log(title = "直播房间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizLiveRoomFormVO form) {
        return toAjax(bizLiveRoomService.updateBizLiveRoom(form));
    }

    /**
     * 删除直播房间
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('biz:room:remove')")
    @Log(title = "直播房间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizLiveRoomService.deleteBizLiveRoomByIds(ids));
    }

    /**
     * 更改状态直播房间
     */
    @ApiOperation("更改状态")
    @PreAuthorize("@ss.hasPermi('biz:room:changeStatus')")
    @Log(title = "直播房间", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody @Valid BizStatusChangeVO vo) {
        return AjaxResult.success(bizLiveRoomService.changeStatus(vo));
    }
}
